// GameTime.cpp
//
// Keeps track of how much time has elapsed since the game has started,
// and allows for pauses without messing up time-based functions.
//
// Nick Kitten
// 2009

#include "GameTime.h"


// Sets the global game time to 0
void GameTime::initialize()
{
	offset = dbTimer();
}

// Gets the current global game time
int GameTime::getTime()
{
	return dbTimer() - offset;
}

// Used in conjunction with stopTimer() to time an event
void GameTime::startTimer()
{
	elapsedTime = getTime();
}

// Returns the elapsed time in ms since startTimer() was called
int GameTime::stopTimer()
{
	elapsedTime = getTime() - elapsedTime;
	return elapsedTime;
}

// Pauses game time
void GameTime::pause()
{
	pauseTime = dbTimer();
}

// Resumes updating of game time
void GameTime::unpause()
{
	pauseTime = dbTimer() - pauseTime;
	offset += pauseTime;
}

// How much time to subtract from dbTimer() to get the
// elapsed game time, not including pauses.
int GameTime::offset = 0;

// At what system time the game was paused
int GameTime::pauseTime = 0;
